import {routers} from "./decoration/InjectRouter";
import Koa from "koa";
import compose from "koa-compose";
import {createConnection} from 'typeorm';

import MD from "./middlewares/index"

createConnection().then(() => {
    const app = new Koa()
    const port = 8088
    app.use(compose(MD));
    app.use(compose(routers)) // 将数组路由改造为promise并挂载

    app.on('error', (err: any, ctx: Koa.Context) => {
        if (ctx) {
            ctx.body = {
                code: 9999,
                message: `程序错误：${err.message}`
            };
        }
    });
    app.listen(port, () => console.log("server run as http://127.0.0.1:" + port));
}).catch((err: string) => console.log('TypeORM connection error:', err));



